﻿<%@page import="com.railway.msg.model.*"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
	<head>
		<title><%=MsgRecive.TABLE_ALIAS%> 维护</title>
	    <%@ include file="/commons/listcssjs.jsp" %>
	   
		<script type="text/javascript"> 

  
	            $(document).ready(function() { 	            
	              if($.browser.msie) {				   
                  }else{
                 //火狐浏览器会存在页面不刷新的问题,因此再查一次,这种处理比较恶心,但是比较见效快
	                $.get("${ctx}/msg/MsgRecive/getReciveMsgs.do?t="+Math.random(), {	            
                        Action:"get",Name:""}, function (data, textStatus){		
                        data = eval('('+data+')');
				        $('#userDataGrid').datagrid("loadData",data);  				              
				});		
				}
							
	        }); 
	        </script>
	</head>
	<body>
		<div style="width: 1000px; padding: 0px;">
			<form id="queryForm" name="queryForm"
				action="${ctx}/msg/MsgRecive/getReciveMsgs.do" method="post"
				style="display: inline;">
				<input type="hidden" id="pageNumber" name="pageNumber" value="1" />
				<input type="hidden" id="pageSize" name="pageSize" value="10" />
				<div class="queryPanel">

				</div>
				<br></br>
				<div>
					<table id="userDataGrid"></table>
					
				</div>
			</form>
		</div>
		
					

   <div id="basedialog"></div>
	</body>
	<script type="text/javascript">
            function openMsgWin(ids){        
           
            var url='${ctx}/msg/MsgSend/create.do'; //要打开的窗口
			var winName="newWin"; //给打开的窗口命名

			// screen.availWidth 获得屏幕宽度
			// screen.availHeight 获得屏幕高度
			// 居中的算法是：
			// 左右居中： (屏幕宽度-窗口宽度)/2
			// 上下居中： (屏幕高度-窗口高度)/2

			var awidth=screen.availWidth/6*4;   //窗口宽度,需要设置
			var aheight=screen.availHeight/5*3;   //窗口高度,需要设置 
			var atop=(screen.availHeight - aheight)/2;    //窗口顶部位置,一般不需要改
			var aleft=(screen.availWidth - awidth)/2; //窗口放中央,一般不需要改

			var param0="scrollbars=0,status=0,menubar=0,resizable=2,location=0"; //新窗口的参数

			//新窗口的左部位置，顶部位置，宽度，高度 
			var params="top=" + atop + ",left=" + aleft + ",width=" + awidth + ",height=" + aheight + "," + param0 ;

			win=window.open(url,winName,params); //打开新窗口
			win.focus(); //新窗口获得焦点 
            
            }
/**用于回调*/
	 function v_deleteItems(result){
			if (result){
				var rows = $('#userDataGrid').datagrid('getSelections');
				var ids = [];
				if(rows!=null&&rows.length>0){
					$.each(rows,function(i,n){ids.push(n.id)
					});
					$.post( "${ctx}/msg/MsgRecive/delete.do", {"items":ids.join(',')}, 
							function(data){
								$.messager.alert('提示','删除成功','info');
								$('#queryForm').submit();
							}
					);
				}else{
			
					$.messager.alert("提示","请选择后进行删除操作！");
				}
			}
		}
		/**
		
		,{
					id:'btnedit',
					text:'回复',
					iconCls:'icon-edit',
					handler:function(){
						var selected = $('#userDataGrid').datagrid('getSelected');
					//	if (selected){
					    var tempid = 0;
							location.href="javascript:openMsgWin('"+tempid+"')";
						//}
					}
				}
			,{field:'id',title:'<%=MsgRecive.ALIAS_ID%>',width:120,sortable:true}			
			,{field:'msgId',title:'<%=MsgRecive.ALIAS_MSG_ID%>',width:120,sortable:true}
			

			
			
			,	{
					id:'btnview',
					text:'查看',
					iconCls:'icon-view',
					handler:function(){
					var selected = $('#userDataGrid').datagrid('getSelected');
	              
				 
							showMsgContent(selected.id ,selected.content) ;
			
	
					}
				}
		**/
		var option = {
				title:'<%=MsgRecive.TABLE_ALIAS%>',
				iconCls:'icon-save',
				width:900,
				height:500,
				nowrap: false,
				striped: true,
				collapsible:true,
				url: "${ctx}/msg/MsgRecive/getReciveMsgs.do?t="+Math.random(),                                                       
				remoteSort: false,
				idField:'id'																				,
				columns:[[
					{field:'ck',checkbox:true}
					,{field:'creator',title:'<%=MsgSend.ALIAS_CREATOR%>',width:120,sortable:true}
					
					,{field:'content',title:'<%=MsgSend.ALIAS_CONTENT%>',width:120,sortable:true,
					formatter:function(val,rec){
 
                           return '<a href="color:red;">('+val+')</span>';
 
                          } 
					}				
					,{field:'status',title:'<%=MsgRecive.ALIAS_STATUS%>',width:120,sortable:true}	
					,{field:'accessoryName',title:'<%=MsgSend.ALIAS_ACCESSORY%>',width:220,sortable:true}						
					,{field:'createTimeString',title:'<%=MsgSend.ALIAS_CREATE_TIME%>',width:120,sortable:true}
					,{field:'readTimeString',title:'<%=MsgRecive.ALIAS_READ_TIME%>',width:120,sortable:true}
				]],
				pagination:true,
				rownumbers:true,
				toolbar:[
				{
					id:'btnview1',
					text:'查看',
					iconCls:'icon-view',
					handler:function(){
					
					var rows = $('#userDataGrid').datagrid('getSelections');
					var ids = [];
					if(rows!=null&&rows.length>0){
					  $.each(rows,function(i,n){ids.push(n.id)});
					  var selected = $('#userDataGrid').datagrid('getSelected');
		
					   var tmp = selected.content;
					 	if (selected){
					 	 
					 	$("#basedialog :text").each(function(){
							$(this).val("")
						})
					 	$('#basedialog').html('<div id ="msgcontent" title  ="消息详情" style= "width:400px;height:200px"></div>');
					      $('#msgcontent').text(tmp);					 	   
					 	  var dialogoptions = {modal:true};					 	   
					 	  $('#msgcontent').dialog(dialogoptions);
					 	  
					 	   if(selected.status == '未读'){
					 	   		$.post( "${ctx}/msg/MsgRecive/updateMsgStatus.do", {"items":ids.join(',')}, 
						 	    function(data){				
								  $('#queryForm').submit();
								  $('#userDataGrid').datagrid('clearSelections');
							    }
					            );
					 	   
					 	   }else{
					 	   //do nothing!
					 	   
					 	   }				 	
					    }			
					
				   }else{
				     	$.messager.alert("提示","请选择后进行查看！");
				    }
	
					}
				},	{
					id:'btnview',
					text:'查看历史接收',
					iconCls:'icon-search',
					handler:function(){
			  		$.get("${ctx}/msg/MsgRecive/getAllReciveMsgs.do", {	            
                        Action:"get",Name:""}, function (data, textStatus){		
                        data = eval('('+data+')');
				        $('#userDataGrid').datagrid("loadData",data);  
					});
					}
				},'-',{
					id:'btndelete',
					text:'删除',
					iconCls:'icon-no',
					handler:function(){
					$.messager.confirm('确认', "确定要删除吗？" ,v_deleteItems);
					}
				},{
					id:'btndownload',
					text:'下载附件',
					iconCls:'icon-save',
					handler:function(){
				    var selected = $('#userDataGrid').datagrid('getSelected');
					if (selected){
					    var tempid = 0;
		
					    if(selected.accessoryPath == null){
					    	$.messager.alert('提示','该消息不包含附件!','info');	 
					    
					    return;
					    }
						location.href="${ctx}/files/Files/download.do?fileTypes=MSG&fileName="+selected.fileId;
						return false;
				    }else{
				       $.messager.alert('提示','请选择一条消息再进行操作!','info');
				    }
					}
				}],
				onLoadSuccess: function(){
	            	function bindRowsEvent(){
		                var panel = $('#userDataGrid').datagrid('getPanel');
		                var rows = panel.find('tr[datagrid-row-index]');
		                rows.unbind('click').bind('click',function(e){
		                    return false;
		                });
		                rows.find('div.datagrid-cell-check input[type=checkbox]').unbind().bind('click', function(e){
		                    var index = $(this).parent().parent().parent().attr('datagrid-row-index');
		                    if ($(this).attr('checked')){
		                        $('#userDataGrid').datagrid('selectRow', index);
		                    } else {
		                        $('#userDataGrid').datagrid('unselectRow', index);
		                    }
		                    e.stopPropagation();
		                });
		            }
		            setTimeout(function(){
		                bindRowsEvent();
		            }, 10);    
	    		}
			}


		//重要$(document).ready(handler)
		$(function(){
			//设置form为ajax提交		
			$('#queryForm').form({
				success:function(data){
				data = eval('('+data+')');
				$('#userDataGrid').datagrid("loadData",data);
				}
			});
			//设置datagrid		
			$('#userDataGrid').datagrid(option);
			//设置底部的上一页和下一页
			var p = $('#userDataGrid').datagrid('getPager');
			if (p){
				$(p).pagination({
					onBeforeRefresh:function(){
					//	alert('before refresh');
					}
				});
				$(p).pagination({
					onSelectPage:function(pageNumber,pageSize){
						$("input[name='pageNumber']").val(pageNumber);
						$("input[name='pageSize']").val(pageSize);
						$('#queryForm').submit();
					}
				});
			}}
		); //end $(document).ready(handler)
		//以下这些方法放在这几是为了提供编写javascript参考用，可根据实际情况删除
		function resize(){
			$('#userDataGrid').datagrid('resize', {
				width:1100,
				height:400
			});
		}
		function getSelected(){
			var selected = $('#userDataGrid').datagrid('getSelected');
			if (selected){
				alert(selected.id);
			}
		}
		function getSelections(){
			var ids = [];
			var rows = $('#userDataGrid').datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
				ids.push(rows[i].id);
			}
			alert(ids.join(':'));
		}
		function clearSelections(){
			$('#userDataGrid').datagrid('clearSelections');
		}
		function selectRow(){
			$('#userDataGrid').datagrid('selectRow',1); //行号从0开始
		}
		function selectRecord(){
			$('#userDataGrid').datagrid('selectRecord','1'); //'1'是id值
		}
		function unselectRow(){
			$('#userDataGrid').datagrid('unselectRow',1);//行号从0开始
		}
	</script>
</html>


